export function getCookie(name) {
  if (document.cookie.length > 0) {
    let start = document.cookie.indexOf(`${name}=`);
    if (start !== -1) {
      start = start + name.length + 1;
      let end = document.cookie.indexOf(';', start);
      if (end === -1) end = document.cookie.length;
      return unescape(document.cookie.substring(start, end));
    }
  }
  return '';
}

export function setCookie(name, value, expiredays) {
  const exdate = new Date();
  exdate.setDate(exdate.getDate() + expiredays);
  document.cookie = `${name}=${escape(value)}${(expiredays === null) ? '' : `;expires=${exdate.toGMTString()}`};path=/`;
}

export function delCookie(name, value) {
  const exdate = new Date();
  exdate.setDate(exdate.getDate() - 1);
  document.cookie = `${name}=${escape(value)};expires=${exdate.toGMTString()}};path=/`;
}
